package com.lanou.wuyou.gift.category;

import android.os.Bundle;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;

import com.google.gson.Gson;
import com.lanou.wuyou.gift.R;
import com.lanou.wuyou.gift.base.BaseFragment;
import com.lanou.wuyou.gift.bean.CategoryDownBean;
import com.lanou.wuyou.gift.bean.CategoryTopBean;
import com.lanou.wuyou.gift.tools.NetResultInterface;
import com.lanou.wuyou.gift.tools.NetWorkInstance;

/**
 * Created by dllo on 17/3/17.
 */

public class CategoryStrategyFragment extends BaseFragment{
    private RecyclerView recyclerView;

    public static CategoryStrategyFragment newInstance (String[] urlT){
        Bundle args = new Bundle();
        args.putString("url",urlT[0]);
        args.putString("url1",urlT[2]);
        CategoryStrategyFragment categoryListFragment = new CategoryStrategyFragment();
        categoryListFragment.setArguments(args);
        return categoryListFragment;
    }
    @Override
    public int setLayout() {
        return R.layout.item_category_main_recycler;
    }

    @Override
    public void initView(View view) {
        recyclerView = (RecyclerView) view.findViewById(R.id.recycler_category_main);
    }

    @Override
    public void initData() {

        final CateListAdapter cateListAdapter = new CateListAdapter(context);
        GridLayoutManager linearLayoutManager = new GridLayoutManager(context,1, LinearLayoutManager.VERTICAL,false);
        recyclerView.setAdapter(cateListAdapter);
        recyclerView.setLayoutManager(linearLayoutManager);
        String urlStr = getArguments().getString("url");
        String urlStr1 = getArguments().getString("url1");
        NetWorkInstance.getInstance().netRequest(urlStr, new NetResultInterface() {
            @Override
            public void success(String str) {
                Gson gson = new Gson();
                CategoryDownBean categoryDownBean = gson.fromJson(str,CategoryDownBean.class);
                cateListAdapter.setCategoryDownBean(categoryDownBean);
            }

            @Override
            public void fail(String str) {

            }
        });
        NetWorkInstance.getInstance().netRequest(urlStr1, new NetResultInterface() {
            @Override
            public void success(String str) {
                Gson gson = new Gson();
                CategoryTopBean categoryTopBean = gson.fromJson(str,CategoryTopBean.class);
                cateListAdapter.setCategoryTopBean(categoryTopBean);

            }

            @Override
            public void fail(String str) {

            }
        });
    }
}
